package com.ssyan.test;

import com.ssyan.sort.Insertion;
import com.ssyan.sort.Merge;
import com.ssyan.sort.Shell;

import java.io.*;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class SortCompare {
    //调用不同的测试方法，完成测试
    public static void main(String[] args) throws IOException {

        List<Integer> list = new ArrayList<Integer>();
        BufferedReader reader = new BufferedReader(new InputStreamReader(SortCompare.class.getClassLoader().getResourceAsStream("reverse_arr.txt")));
        String line = null;
        while ((line=reader.readLine()) != null) {
            //line是字符串，把line转换为Integer，存储到集合中
            int i = Integer.parseInt(line);
            list.add(i);
        }
        reader.close();

        //System.out.println(list);

        Integer[] a = list.stream().toArray(Integer[]::new);

        //测试
        //testShell(a);
        //testInsertion(a);
        testMerge(a);
    }

    //测试希尔排序
    public static void testShell(Integer[] a) {
        long start = System.currentTimeMillis();
        Shell.sort(a);
        long end = System.currentTimeMillis();
        System.out.println("希尔排序执行的时间为："+(end-start)+"毫秒");
    }

    //测试插入排序
    public static void testInsertion(Integer[] a) {
        long start = System.currentTimeMillis();
        Insertion.sort(a);
        long end = System.currentTimeMillis();
        System.out.println("插入排序执行的时间为："+(end-start)+"毫秒");
    }

    //测试归并排序
    public static void testMerge(Integer[] a) {
        long start = System.currentTimeMillis();
        Merge.sort(a);
        long end = System.currentTimeMillis();
        System.out.println("归并排序执行的时间为："+(end-start)+"毫秒");
    }
}
